package customer;

import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.opensymphony.xwork2.ActionSupport;

import connection.MyConnection;

public class Customer_Entry extends ActionSupport {
	
	public String name;
	public String phone;
	public String gender;
	public double payment;
	public double paidpayment;
	public double remainpayment;
	public String address;
	public String date;
	public String product;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public double getPayment() {
		return payment;
	}
	public void setPayment(double payment) {
		this.payment = payment;
	}
	public double getPaidpayment() {
		return paidpayment;
	}
	public void setPaidpayment(double paidpayment) {
		this.paidpayment = paidpayment;
	}
	public double getRemainpayment() {
		return remainpayment;
	}
	public void setRemainpayment(double remainpayment) {
		this.remainpayment = remainpayment;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getDate() {
		return date;
	}
	public void setDate(String date) {
		this.date = date;
	}
	public String getProduct(){
		return product;
	}
	public void setProduct(String product){
		this.product = product;
	}
	@Override
	
	public String execute() throws Exception 
	{
		MyConnection mc = new MyConnection();
		mc.connect();
		
		Date d = new Date();
		SimpleDateFormat sf = new SimpleDateFormat("dd//MM//yyyy");
		String date = sf.format(d).toString();
		
		try
		{
			PreparedStatement ps = mc.con.prepareStatement("insert into customer(name, phone, gender,totalpayment, paidpayment, remaining_payment, address, date, product) values(?,?,?,?,?,?,?,?,?)");
			ps.setString(1, name);
			ps.setString(2, phone);
			ps.setString(3, gender);
			ps.setDouble(4, payment);
			ps.setDouble(5, paidpayment);
			ps.setDouble(6, remainpayment);
			ps.setString(7, address);
			ps.setString(8, date);
			ps.setString(9, product);
			ps.executeUpdate();
			
		}
		
		catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
		return "success";
	}

}
